home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1996-06-21 | 5.8 KB | 223 lines | [TEXT/ALFA] |
- IMPLEMENTATION MODULE RMSDebugHelp;
-
- (*
- Implementation and Revisions:
- ============================
-
- Author Date Description
- ------ ---- -----------
-
- AF 21/10/90 First implementation (DM 2.01, MacMETH 2.6+)
-
- or 23/05/91 uses now DMOpSys and DMMessages instead of DMSubLaunch
- af 11/05/93 ActivateHeapTrace added (new key)
- *)
-
- FROM SYSTEM IMPORT ADDRESS, VAL;
- FROM DMMessages IMPORT Inform, Warn;
- FROM DMConversions IMPORT IntToString, LongIntToString;
- FROM DMSystem IMPORT startUpLevel, maxLevel, CurrentDMLevel,
- InstallTermProc, InstallInitProc;
- FROM DMStrings IMPORT Append, AppendCh;
- FROM DMHeapWatch IMPORT showLevels, blockSizes, allocInfoProc, debugProc;
-
- (*. (* needed for implementation of ActivateHeapTrace *)
- FROM SYSTEM IMPORT ADDRESS, VAL;
- FROM DMFiles IMPORT TextFile,
- WriteChars, WriteChar, WriteEOL, Close;
- .*)
-
- VAR
- installed: BOOLEAN;
- alreadyHalted: ARRAY [startUpLevel..maxLevel] OF BOOLEAN;
-
- VAR
- startLev: CARDINAL;
-
-
-
- PROCEDURE ShowLevels (procName: ARRAY OF CHAR; anInt: INTEGER; size: LONGINT);
- VAR str1, str2: ARRAY [0..63] OF CHAR; istr: ARRAY [0..23] OF CHAR;
- BEGIN
- str1 := 'In ';
- Append(str1,procName);
- AppendCh(str1,':');
-
- str2 := 'anInt=';
- IntToString(anInt,istr,0);
- Append(str2,istr);
-
- str2 := 'size=';
- LongIntToString(size,istr,0);
- Append(str2,istr);
-
- Append(str2,' CurrentDMLevel()=');
- IntToString(CurrentDMLevel(),istr,0);
- Append(str2,istr);
-
- Inform( str1, str2, "" );
-
- IF NOT alreadyHalted[CurrentDMLevel()] THEN
- alreadyHalted[CurrentDMLevel()]:= TRUE; Warn(str1,str2,"");
- END;
- END ShowLevels;
-
- PROCEDURE ShowCaller (procName: ARRAY OF CHAR; level: INTEGER;
- size: LONGINT);
- VAR str1, str2: ARRAY [0..63] OF CHAR; istr: ARRAY [0..23] OF CHAR;
- BEGIN
- str1 := 'In ';
- Append(str1,procName);
- AppendCh(str1,':');
-
- str2 := 'level=';
- IntToString(level,istr,0);
- Append(str2,istr);
-
- str2 := 'size=';
- LongIntToString(size,istr,0);
- Append(str2,istr);
-
- Append(str2,' CurrentDMLevel()=');
- IntToString(CurrentDMLevel(),istr,0);
- Append(str2,istr);
-
- Inform( str1, str2, "" );
-
- (*. IF NOT alreadyHalted[CurrentDMLevel()] THEN
- alreadyHalted[CurrentDMLevel()]:= TRUE; HALT;
- END; .*)
- Warn(str1,str2,"");
- END ShowCaller;
-
-
- CONST
- TAB = 11C ;
-
- (*. (* needed for implementation of ActivateHeapTrace *)
- VAR
- outF: TextFile;
- str: ARRAY [0..31] OF CHAR;
-
- PROCEDURE AllocInfoP( pBefore, pAfter: ADDRESS; size: LONGINT; lev: INTEGER);
- BEGIN
- WriteChar( outF, "A" );
- WriteChar( outF, TAB );
- (* old address *)
- LongIntToString( VAL(LONGINT,pBefore), str, 1 );
- WriteChars( outF, str );
- WriteChar( outF, TAB );
- (* size *)
- LongIntToString( size, str, 1 );
- WriteChars( outF, str );
- WriteChar( outF, TAB );
- (* level *)
- IntToString( lev, str, 1 );
- WriteChars( outF, str );
- WriteChar( outF, TAB );
- (* new address *)
- LongIntToString( VAL(LONGINT,pAfter), str, 1 );
- WriteChars( outF, str );
- WriteEOL( outF );
- END AllocInfoP;
-
- PROCEDURE DeallocInfoP(pBefore, pAfter: ADDRESS; level: INTEGER);
- BEGIN
- WriteChar( outF, "D" );
- WriteChar( outF, TAB );
- (* the address AFTER dealloc *)
- LongIntToString( VAL(LONGINT,pAfter), str, 1 );
- WriteChars( outF, str );
- WriteChar( outF, TAB );
- (* size *)
- WriteChar( outF, TAB );
- (* level *)
- IntToString( level, str, 1 );
- WriteChars( outF, str );
- WriteChar( outF, TAB );
- (* the address BEFORE dealloc *)
- LongIntToString( VAL(LONGINT,pBefore), str, 1 );
- WriteChars( outF, str );
- WriteEOL( outF );
- END DeallocInfoP;
-
- PROCEDURE CloseOutF;
- BEGIN
- Close( outF )
- END CloseOutF;
-
- .*)
-
- PROCEDURE CloseOutF;
- BEGIN
- END CloseOutF;
-
- PROCEDURE ActivateHeapTrace;
- BEGIN
- (*. (* needed for implementation of ActivateHeapTrace *)
- Lookup( outF, "DMStorage - DEBUG OUT", TRUE );
- WriteChars( outF, "Alloc / Dealloc" );
- WriteChar( outF, TAB );
- WriteChars( outF, "before A / after D" );
- WriteChar( outF, TAB );
- WriteChars( outF, "size / -- " );
- WriteChar( outF, TAB );
- WriteChars( outF, "level / level" );
- WriteChar( outF, TAB );
- WriteChars( outF, "after A / before D" );
- WriteEOL( outF );
- allocInfoProc:=AllocInfoP;
- deallocInfoProc:=DeallocInfoP;
- .*)
- END ActivateHeapTrace;
-
- (*.
- PROCEDURE AllocateHalt( pBefore, pAfter: ADDRESS; size: LONGINT; lev: INTEGER);
- VAR msg: ARRAY [0..255] OF CHAR; str: ARRAY [0..31] OF CHAR;
- BEGIN
- IF size<>1032D THEN
- RETURN
- END(*IF*);
- msg := "A";
- AppendCh( msg, TAB );
- (* old address *)
- LongIntToString( VAL(LONGINT,pBefore), str, 1 );
- Append(msg, str );
- AppendCh(msg, TAB );
- (* size *)
- LongIntToString( size, str, 1 );
- Append(msg, str );
- AppendCh(msg, TAB );
- (* level *)
- IntToString( lev, str, 1 );
- Append(msg, str );
- AppendCh(msg, TAB );
- (* new address *)
- LongIntToString( VAL(LONGINT,pAfter), str, 1 );
- Append(msg, str );
-
- Warn(msg,"","");
- END AllocateHalt;
- .*)
-
- PROCEDURE AtInit;
- BEGIN
- alreadyHalted[CurrentDMLevel()] := FALSE;
- END AtInit;
-
- PROCEDURE AtTerm;
- BEGIN
- IF CurrentDMLevel()=startLev THEN CloseOutF END;
- END AtTerm;
-
- BEGIN
- alreadyHalted[CurrentDMLevel()]:= FALSE;
- InstallInitProc (AtInit,installed);
- InstallTermProc (AtTerm,installed);
- showLevels := ShowLevels;
- blockSizes[0] := 0D; (* shown at allocation if same size *)
- blockSizes[1] := 0D; (* shown at allocation if same size *)
- debugProc := ShowCaller;
- startLev := CurrentDMLevel();
- END RMSDebugHelp.